import codecs


class EncodingConverter:
    def __init__(self):
        pass

    def convert_utf8_to_gbk(self,input_file, output_file):
        try:
            with codecs.open(input_file, 'r', 'utf-8') as f:
                content = f.read()

            with codecs.open(output_file, 'w', 'gbk', errors='replace') as f:
                f.write(content)

            print(f"Conversion successful: {input_file} (UTF-8) -> {output_file} (GBK)")
        except Exception as e:
            print(f"Error during conversion: {e}")


# 使用示例
if __name__ == "__main__":
    input_file = './data.sql'  # 输入文件名，假设是UTF-8编码
    output_file = './output.sql'  # 输出文件名，转换为GBK编码

    converter = EncodingConverter()
    converter.convert_utf8_to_gbk(input_file, output_file)